home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_07 / 2n07038b < prev    next >
Text File  |  1991-06-01  |  6KB  |  193 lines

  1. /*
  2.  *   Main windows routines for the Animated Cursor Demo Program
  3.  *
  4.  * Written by Alex Leavens, for ShadowCat Technologies
  5.  *
  6.  * Created: 10/May/91
  7.  * Revised: 14/May/91
  8.  *
  9.  */
  10.  
  11.  
  12. #include <WINDOWS.H>
  13. #include "CURSOR.H"
  14.  
  15. /*----------------------- Function prototypes -----------------*/
  16.  
  17. long FAR PASCAL HandleCursorSet(HWND, unsigned, WORD, LONG);
  18.  
  19. /*----------------------- Global Variables --------------------*/
  20.  
  21. HANDLE  hInst   = 0;  /* Handle to the instance of our program */
  22. HWND    MainhWnd= 0;  /* Handle to the main window of our program */
  23.  
  24. /***************************
  25.  *
  26.  * WinMain()
  27.  *    Entry point for any windows program.
  28.  *
  29.  */
  30.   
  31.     int PASCAL
  32. WinMain(HANDLE  hInstance,      /* Current instance of program */
  33.         HANDLE  hPrevInstance,  /* Any previous instance of the program */
  34.         LPSTR   lpCmdLine,      /* Pointer to any command line args */
  35.         int     nCmdShow)       /* Show window type (open or iconic) */
  36. {
  37.     MSG msg;                    /* Messages from the system */
  38.  
  39.     /*------------------------------------------*/
  40.  
  41.     hInst = hInstance;          /* Save current instance */
  42.     
  43.     if (!hPrevInstance)         /* Is there an other instance of the task   */
  44.     {
  45.         if (!CurRegisterClass(hInstance))
  46.             return FALSE;       /* Punt if Class registration failed */
  47.     }
  48.  
  49.     MainhWnd = CurCreateWindow(hInstance);
  50.     if (!MainhWnd)              /* If we couldn't create the window, punt */
  51.         return FALSE;
  52.  
  53.     ShowWindow(MainhWnd, nCmdShow);  /* Show the window */
  54.     UpdateWindow(MainhWnd);          /* Send WM_PAINT message to window */
  55.  
  56.     SendMessage(MainhWnd,
  57.                 WM_COMMAND,
  58.                 IDM_Speed1,
  59.                 (LONG)0);       /* Send speed1 a message to check itself */
  60.  
  61.     while (GetMessage(&msg,     /* place to put message info */
  62.         0,                      /* get messages to all windows */
  63.         0,                      /* examine all messages, from lowest to */
  64.         0))                     /* highest */
  65.     {
  66.         TranslateMessage(&msg); /* Translates character keys                */
  67.         DispatchMessage(&msg);  /* Dispatches message to window             */
  68.     }
  69.  
  70.     return(msg.wParam);         /* Returns the value from PostQuitMessage   */
  71. }
  72. /**************************
  73.  *
  74.  * MainWndProc()
  75.  *    Handles the main event messaging loop that we use
  76.  * to process windows messages.
  77.  *
  78.  */
  79.  
  80.     long FAR PASCAL
  81. MainWndProc(HWND        hWnd,
  82.             unsigned    message,
  83.             WORD        wParam,
  84.             LONG        lParam)
  85. {
  86.  
  87.     switch (message)
  88.     {
  89.         case WM_SETCURSOR:                      /* Special cursor set message */
  90.             return HandleCursorSet(hWnd, 
  91.                                    message, 
  92.                                    wParam, 
  93.                                    lParam);
  94.             break;
  95.  
  96.         case WM_DESTROY:            /* Shutdown time... */
  97.             PostQuitMessage(0);
  98.             return DefWindowProc(hWnd, message, wParam, lParam);
  99.             break;
  100.  
  101.         case WM_COMMAND:            /* Command from main window (handles menus) */
  102.             switch(wParam)
  103.             {
  104.                 case IDM_Animate:
  105.                     Animate(hWnd,message,wParam,lParam);
  106.                     break;
  107.                 case IDM_Speed1:
  108.                 case IDM_Speed2:
  109.                 case IDM_Speed3:
  110.                 case IDM_Speed4:
  111.                     SetSpeed(hWnd,message,wParam,lParam);
  112.                     break;
  113.                 case IDM_Quit:
  114.                     QuitFunc(hWnd,message,wParam,lParam);
  115.                     break;
  116.                 default:
  117.                     break;
  118.             }
  119.             break;
  120.  
  121.         default:                        /* Just let windows handle it... */
  122.             return DefWindowProc(hWnd, message, wParam, lParam);
  123.             break;
  124.             
  125.     }
  126.     return FALSE;               /* Returns FALSE if processed               */
  127. }
  128. /***************************
  129.  *
  130.  * CurRegisterClass()
  131.  *    Registers the class for our main window.  Done only if
  132.  * there isn't another instance of the application already running.
  133.  */
  134.  
  135.     BOOL
  136. CurRegisterClass(HANDLE hInstance)
  137. {
  138.     WNDCLASS    WndClass;       /* Window class structure to fill in */
  139.  
  140.     /*-----------------------------*/
  141.   
  142.     WndClass.style         = 0;
  143.     WndClass.lpfnWndProc   = MainWndProc;
  144.     WndClass.cbClsExtra    = 0;
  145.     WndClass.cbWndExtra    = 0;
  146.     WndClass.hInstance     = hInstance;
  147.     WndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  148.     WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  149.     WndClass.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  150.     WndClass.lpszMenuName  = "CURSOR";
  151.     WndClass.lpszClassName = "CURSOR";
  152.  
  153.     return RegisterClass(&WndClass);
  154. }
  155. /********************************
  156.  *
  157.  * CurCreateWindow()
  158.  *   Creates the window for our application
  159.  */
  160.  
  161.     HWND
  162. CurCreateWindow(HANDLE  hInstance)
  163. {
  164.     HWND        hWnd;           /* Handle to the created window */
  165.     int         coordinate[4];  /* Coordinates of the window (use system defaults) */
  166.  
  167.     /*-----------------------------------*/
  168.  
  169.     coordinate[0]=CW_USEDEFAULT;
  170.     coordinate[1]=0;
  171.     coordinate[2]=CW_USEDEFAULT;
  172.     coordinate[3]=0;
  173.     
  174.     hWnd = CreateWindow("CURSOR",
  175.            "Animated Cursor Demo Program",
  176.  
  177.            WS_OVERLAPPED | WS_THICKFRAME |
  178.            WS_SYSMENU | WS_MINIMIZEBOX |
  179.            WS_MAXIMIZEBOX,
  180.  
  181.            coordinate[0],        /* x position */
  182.            coordinate[1],        /* y position */
  183.            coordinate[2],        /* width      */
  184.            coordinate[3],        /* height     */
  185.            0,                    /* No parent to this window */
  186.            0,                    /* No children either... */
  187.            hInstance,            /* application instance... */
  188.            (LPSTR)NULL);         /* no additional data */
  189.     
  190.     return hWnd;
  191. }
  192.  
  193.